package cn.tedu.aop.base.advice;
import cn.tedu.aop.base.response.JsonResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public JsonResult handleMethodArgumentException(MethodArgumentNotValidException e)
    {
        e.printStackTrace();
        return new JsonResult(0,e.getFieldError().getDefaultMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public JsonResult handleRuntimeException(RuntimeException e)
    {
        e.printStackTrace();
        return new JsonResult(0,e.getMessage());
    }

}
